<?php
/**
 * KayPaste
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * @category   KayPaste
 * @package    Controller
 * @subpackage Action Helpers
 * @copyright  Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author     Robin Skoglund
 */

/**
 * Imports
 */
require_once 'Zend/Controller/Action/Helper/Abstract.php';
require_once 'Zend/Session/Namespace.php';

/**
 * An action helper for wrapping a global application session namespace
 * 
 * @category   KayPaste
 * @package    Controller
 * @subpackage Action Helpers
 * @copyright  Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author     Robin Skoglund
 */
class Kaypaste_Controller_Action_Helper_AppSession
    extends Zend_Controller_Action_Helper_Abstract
{
    const DEFAULT_NAMESPACE = 'application';
    
    /**
     * Session namespace
     *
     * @var Zend_Session_Namespace
     */
    protected $_session;

    /**
     * Creates the action helper, optionally setting namespace name
     *
     * @param string $namespace  [optional] defaults to 'application'
     */
    public function __construct($namespace = null)
    {
        if (!is_string($namespace)) {
            $namespace = self::DEFAULT_NAMESPACE;
        }
        
        $this->_session = new Zend_Session_Namespace($namespace);
    }
    
    /**
     * Returns application global session namespace
     *
     * @return Zend_Session_Namespace
     */
    public function getSession()
    {
        return $this->_session;
    }
    
    /**
     * Strategy pattern: Return session namespace
     *
     * @return Zend_Session_Namespace  session namespace
     */
    public function direct()
    {
        return $this->getSession();
    }
}
